const { setItem, getItem } = require('../common/platform');

const USER_INFO = 'local_user_info';

const setUserInfo = (userInfo) => {
    setItem(USER_INFO, userInfo);
};

const getUserInfo = () => {
    return getItem(USER_INFO);
};

const USER_TOKEN = 'local_user_token';

const setUserToken = (token) => {
    setItem(USER_TOKEN, token)
};

const getUserToken = () => {
    return getItem(USER_TOKEN);
};

const MODE_VALUE = 'local_mode_value';

/**
 * 设置模式
 * @param {String} mode 模式
 */
const setMode = (mode) => {
    setItem(MODE_VALUE, mode);
};

/**
 * 获取模式值
 */
const getMode = () => {
    return getItem(MODE_VALUE);
};

const THEME_VALUE = 'local_theme_value';

/**
 * 设置主题颜色值
 * @param {String} theme 颜色值
 */
const setTheme = (theme) => {
    setItem(THEME_VALUE, theme);
};

/**
 * 获取主题颜色值
 */
const getTheme = () => {
    return getItem(THEME_VALUE);
};

const STYLE_MODE_VALUE = 'local_style_mode_value';

/**
 * 设置主题样式
 * @param {String} styleMode 主题样式
 */
const setStyleMode = (styleMode) => {
    setItem(STYLE_MODE_VALUE, styleMode);
};

/**
 * 获取主题模式
 */
const getStyleMode = () => {
    return getItem(STYLE_MODE_VALUE);
};

const LOCAL_DATA_LOCATION = 'local_data_location_value';

const setLocationValue = (locationInfo) => {
    setItem(LOCAL_DATA_LOCATION, locationInfo);
};

const getLocationValue = () => {
    return getItem(LOCAL_DATA_LOCATION);
};

const LOCAL_DATA_LOCATION_FLAG = 'local_data_location_flag';

const setLocationFailFlag = (flag) => {
    setItem(LOCAL_DATA_LOCATION_FLAG, flag);
};

const getLocationFailFlag = () => {
    const value = getItem(LOCAL_DATA_LOCATION_FLAG);
    return value !== '' ? value : true;
};

module.exports = {
    setUserInfo,
    getUserInfo,
    setUserToken,
    getUserToken,
    setMode,
    getMode,
    setTheme,
    getTheme,
    setStyleMode,
    getStyleMode,
    setLocationValue,
    getLocationValue,
    setLocationFailFlag,
    getLocationFailFlag,
};